<template>
  <j-modal
    :title="title"
    :width="width"
    :fullscreen=true
    :footer="footer"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model">
        <a-row>
          <f-render
            @save="handleSave"
            :loading="loading"
            height="calc(100vh - 60px)"
            :config="formConfig"
          />
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { getAction,postAction,putAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  export default {
    name: 'DesignFormModal',
    components: {
    },
    data () {
      return {
        title:"设计表单",
        width:"1600",
        footer:"null",
        visible: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,

        loading: false,
        formConfig: {},

        url: {
          add: "/desform/lbDesform/add",
          edit: "/desform/lbDesform/edit",
        }

      }
    },
    created () {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    mounted() {
    },
    methods: {
      handleSave(res) {
        console.log(res);
        const that = this;
        that.model.desformDesignJson=res;
        putAction(this.url.edit,that.model).then((res)=>{
          if(res.success){
            that.$message.success(res.message);
            that.$emit('ok');
          }else{
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.confirmLoading = false;
          that.close();
        })
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.loading = false;
        this.formConfig = JSON.parse(this.model.desformDesignJson) || "";
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        this.close()
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>